import App from './App'
import uniNavbar from "./components/uni-navbar"
import store from './store'
import * as utils from './utils'
import WxmpRsa from 'wxmp-rsa'
import uView from './uni_modules/uview-ui';

// #ifndef VUE3
import Vue from 'vue'
import * as filters from './filters'
Vue.config.productionTip = false

Object.keys(filters).forEach(key => {
	Vue.filter(key, filters[key])
})

Vue.use(uView);
Vue.component('uni-navbar', uniNavbar)

Vue.prototype.$store = store

Object.keys(utils).forEach(key => {
	Vue.prototype["$" + key] = utils[key]
})

Vue.prototype.$rsa = function(value) {
	const rsa = new WxmpRsa()
	rsa.setPublicKey(
		'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMriq7pzPIZ3ug65eEb1samm+RsqfIUUqUHLafLWqHzdH35FfpvuycnLP82Rb0EXoaUvNR7EQbVJO9v6gzGEL1qylit5YL2TdNwWw/5ZKcn6PbDHwVJeqHuEWls+aPPnWqVJxrXJ77BuSyZrx3CjE4EDATxTt2PwZ/CwYzpjK1DQIDAQAB'
	)
	return rsa.encrypt(value)
}

App.mpType = 'app'
const app = new Vue({
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'

export function createApp() {
	const app = createSSRApp(App)
	app.use(uView)
	app.use(store)
	app.component('uni-navbar', uniNavbar)

	Object.keys(utils).forEach(key => {
		app.config.globalProperties["$" + key] = utils[key]
	})

	app.config.globalProperties.$rsa = function(value) {
		const rsa = new WxmpRsa()
		rsa.setPublicKey(
			'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMriq7pzPIZ3ug65eEb1samm+RsqfIUUqUHLafLWqHzdH35FfpvuycnLP82Rb0EXoaUvNR7EQbVJO9v6gzGEL1qylit5YL2TdNwWw/5ZKcn6PbDHwVJeqHuEWls+aPPnWqVJxrXJ77BuSyZrx3CjE4EDATxTt2PwZ/CwYzpjK1DQIDAQAB'
		)
		return rsa.encrypt(value)
	}

	return {
		app
	}
}
// #endif
